<template>
  <div class="publicpageview">
    <div class="publicformview">
      <el-form label-width="140px" :inline="true" :model="listQuery" size="mini" ref="searchForm">
        <el-row :gutter="10">
          <el-col :span="4">
            <el-form-item label="状态：" prop="State">
              <el-select clearable v-model="listQuery.State">
                <el-option label="未提交" value="00" key="00"></el-option>
                <el-option label="抽查通过" value="40" key="40"></el-option>
                <el-option label="区住建委核查通过" value="50" key="50"></el-option>
                <el-option label="抽查不通过" value="-2" key="-2"></el-option>
                <el-option label="等待区住建委核查" value="20" key="20"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="承租人：" prop="Owner">
              <el-input clearable v-model="listQuery.Owner"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="房屋地址：" prop="Addr">
              <el-input clearable v-model="listQuery.Addr"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="业务编号：" prop="FCode">
              <el-input clearable v-model="listQuery.FCode"></el-input>
            </el-form-item>
          </el-col>
          <div v-show="isSearch">
            <el-col :span="8">
              <el-form-item label="管理部(分中心)核对时间：" prop="FGZManagerDate" label-width="240px">
                <el-date-picker clearable v-model="listQuery.FGZManagerDate" type="date" placeholder="年/月/日">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="区住建委核查时间：" prop="QGSDate" label-width="170px">
                <el-date-picker clearable v-model="listQuery.QGSDate" type="date" placeholder="年/月/日">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </div>

          <el-col :span="5">
            <div>
              <el-button size="mini" type="primary" @click="chaxun">查询</el-button>
              <el-button size="mini" @click="resetForm">重置</el-button>
              <el-button size="mini" type="primary" @click="isSearch = !isSearch">{{!isSearch?'高级搜索':'关闭搜索'}}</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>

    <div class="publitableview">
      <el-button type="primary" size="mini" @click="handleAddUser('登记')">分户登记</el-button>
      <!-- <el-button type="primary" size="mini" @click="handleout">导出</el-button> -->
      <!-- <el-button type="primary" size="mini"  v-print="printObj">打印</el-button> -->
      <div id="loading" v-show="printLoading"></div>
      <el-table id="publicpageview" v-loading="listLoading" :data="list" border fit highlight-current-row size="mini">
        <el-table-column align="center" label="管理部(分中心)" prop="houseAdminName">
        </el-table-column>

        <el-table-column align="center" label="合同编号" prop="contractno">
        </el-table-column>

        <el-table-column align="center" label="业务编号" prop="fcode">
        </el-table-column>

        <el-table-column align="center" label="承租人" prop="owner">
        </el-table-column>

        <el-table-column align="center" label="房屋地址" prop="addr">
        </el-table-column>

        <el-table-column align="center" label="产别" prop="realway">
        </el-table-column>

        <el-table-column align="center" label="房管站核实时间" prop="fgzmanagerdate">
          <template slot-scope="scope">
            {{scope.row.fgzmanagerdate?scope.row.fgzmanagerdate.split(' ')[0]:''}}
          </template>
        </el-table-column>

        <el-table-column align="center" label="状态" prop="state">
          <template slot-scope="scope">
            {{scope.row.state==-1?'区住建委退回':scope.row.state==-2?'抽查不通过':scope.row.state=='00'?'未提交':
              scope.row.state==10?'数据录入完毕':scope.row.state==20?'等待区住建委核查':scope.row.state==40?'抽查通过':
                  scope.row.state==50?'区住建委核查通过':''}}
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="340">
          <template slot-scope="scope">
<!--            <el-button v-if="scope.row.state=='00'" type="text" size="mini" @click="handleTijiao(scope.row.fid)">提交</el-button>-->
<!--            <el-button v-if="scope.row.state=='10'||scope.row.state==-1" type="text" size="mini" @click="handleAddUser('房管',scope.row.fid)">房管站审核</el-button>-->
<!--            <el-button v-if="scope.row.state=='20'||scope.row.state==-2" type="text" size="mini" @click="handleAddUser('复核',scope.row.fid)">区建委审核</el-button>-->
            <el-button type="text" size="mini" @click="handleAddUser('flow',scope.row.fid)">审核</el-button>
<!--            <el-button type="text" size="mini" @click="handleAddUser('修改',scope.row.fid)">修改</el-button>-->
<!--            <el-button type="text" size="mini" @click="handleAddUser('详情',scope.row.fid)">详情</el-button>-->
<!--            <el-button type="text" size="mini" @click="handleDelete(scope.row.fid)">删除</el-button>-->
          </template>
        </el-table-column>
      </el-table>

      <div class="publicpaginationview">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                       :current-page="listQuery.pageNum" background :page-sizes="[10, 20, 50, 100]" :page-size="listQuery.pageSize"
                       layout="total, sizes, prev, pager, next, jumper" :total="total" small></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import dayjs from 'dayjs'
import * as XLSX from 'xlsx'
import {
  splittingFamilyList,
  addSplittingFamily,
  splittingFamilySubmit,
  splittingFamilyData,
  updSplittingFamily,
  delSplittingFamilySubmit
} from '@/api/management'
import managementFileUpload from '@/components/managementFileUpload.vue';
import {queryisAction, queryloginfzarea} from "@/api/workflow/jfFlowable";
export default {
  name: "AccommodationManagementChanquanzhengjian",
  components: {
    managementFileUpload
  },
  data() {
    return {
      listQuery: {
        pageNum: 1,
        pageSize: 20,
        State: '',
        Owner: '',
        Addr: '',
        FCode: '',
        FGZManagerDate: '',
        QGSDate: ''
      },
      total: 0,
      options: [{
        key: "1"
      }],
      addQuery: {
        contractno: '',
        fcode: '',
        owner: '',
        idcard1: '',
        addr: '',
        realway: '',
        roomcount: '',
        roomno: '',
        jizumianji: '',
        singlearea: '',
        mixarea: '',
        renter1: '',
        memo: '',
        ImgUpload:'',
        material: '否',
        disagree: '否',
        owe: '否',
        contract: '否',
        destroy: '否',
        city: '否',
        change: '否'
      },
      rules: {
        contractno: [
          { required: true, message: '请输入合同编号', trigger: 'blur' }
        ],
        fcode: [
          { required: true, message: '请输入业务编号', trigger: 'blur' }
        ],
        owner: [
          { required: true, message: '请输入承租人', trigger: 'blur' }
        ],
        idcard1: [
          { required: true, message: '请输入承租人身份证号', trigger: 'blur' }
        ],
        addr: [
          { required: true, message: '请输入房屋地址', trigger: 'blur' }
        ],
        realway: [
          { required: true, message: '请输入产别', trigger: 'blur' }
        ],
        roomcount: [
          { required: true, message: '请输入间数', trigger: 'blur' }
        ],
        roomno: [
          { required: true, message: '请输入间号', trigger: 'blur' }
        ],
        jizumianji: [
          { required: true, message: '请输入计租面积', trigger: 'blur' }
        ],
        singlearea: [
          { required: true, message: '请输入独用', trigger: 'blur' }
        ],
        mixarea: [
          { required: true, message: '请输入伙用', trigger: 'blur' }
        ],
        renter1: [
          { required: true, message: '请输入申请人', trigger: 'blur' }
        ],
        memo: [
          { required: true, message: '请输入备注', trigger: 'blur' }
        ]
      },
      fuheQuery: {
        qgsview: '',
        qgscheck: '',
        qgsdate: ''
      },
      shenheQuery: {
        zgsdate: '',
        zgsview: '',
        zgscheck: ''
      },
      newAddQuery: {},
      list: [],
      listLoading: false,
      dialogVisible: false,
      addQueryle: false,
      shenheName: '经营管理意见',
      type: '',
      uploadDialogVisible: false,
      dialogName: '',
      typeName: '',
      fid: '',
      isSearch:false,
      uploadAction: 'http://125.39.77.18:9021/mall-admin/fileUpload/upload',

      printLoading: true,
      printObj: {
        id: "publicpageview",
        popTitle: '打印预览',
        extraCss: "https://cdn.bootcdn.net/ajax/libs/animate.css/4.1.1/animate.compat.css",
        beforeOpenCallback(vue) {
          console.log('打开之前')
        },
        openCallback(vue) {
          console.log('执行了打印')
        },
        closeCallback(vue) {
          console.log('关闭了打印工具')
        }
      },
      showids:[],//可以显示的ids
    };
  },

  computed: {

  },

  mounted() {
    this.newAddQuery = JSON.stringify(this.addQuery)
    this.splittingFamilyList()
  },
  created() {


  },
  methods: {
    chaxun() {
      this.splittingFamilyList()
    },
    // 分户列表
    splittingFamilyList() {
      let data = {
        pageNum: this.listQuery.pageNum,
        pageSize: this.listQuery.pageSize,
        State: this.listQuery.State,
        Owner: this.listQuery.Owner,
        Addr: this.listQuery.Addr,
        FCode: this.listQuery.FCode,
        FGZManagerDate: this.listQuery.FGZManagerDate ? dayjs(this.listQuery.FGZManagerDate).format(
            'YYYY-MM-DD HH:mm:ss') : '',
        QGSDate: this.listQuery.QGSDate ? dayjs(this.listQuery.QGSDate).format('YYYY-MM-DD HH:mm:ss') : ''
      }
      this.listLoading = true;

      // var res={
      //   code: 200,
      //   message: "操作成功",
      //   data: {
      //     pageNum: 1,
      //     pageSize: 20,
      //     totalPage: 1,
      //     total: 4,
      //     list: [
      //       {
      //         fid: 3000030,
      //         fidold: null,
      //         fcode: "2025经非分字1号",
      //         blockgroup: "小白楼测试房管员01",
      //         owner: "13",
      //         addr: "测测测白楼0001",
      //         realway: "代管产",
      //         roomcount: 1,
      //         roomno: "102",
      //         contractno: "01090021131330",
      //         singlearea: 120,
      //         mixarea: 100,
      //         renter1: null,
      //         singlearea1: null,
      //         mixarea1: null,
      //         roomcount1: null,
      //         roomno1: null,
      //         renter2: null,
      //         singlearea2: null,
      //         mixarea2: null,
      //         roomcount2: null,
      //         roomno2: null,
      //         renter3: null,
      //         singlearea3: null,
      //         mixarea3: null,
      //         roomcount3: null,
      //         roomno3: null,
      //         material: "是",
      //         material1: null,
      //         contract: "否",
      //         contract1: null,
      //         change: "否",
      //         change1: null,
      //         owe: "否",
      //         owe1: null,
      //         destroy: "否",
      //         destroy1: null,
      //         disagree: "否",
      //         disagree1: null,
      //         city: "否",
      //         city1: null,
      //         fgzname: null,
      //         fgzcheckview: "同意",
      //         fgzcheck: "admin",
      //         fgzcheckdate: "2025-10-16 15:15:30",
      //         fgzmanagerview: null,
      //         fgzmanager: null,
      //         fgzmanagerdate: null,
      //         qgsname: null,
      //         qgsview: null,
      //         qgsview1: null,
      //         qgscheck: null,
      //         qgsdate: null,
      //         qgsdate1: null,
      //         zgsview: null,
      //         zgsview1: null,
      //         zgscheck: null,
      //         zgsdate: null,
      //         zgsdate1: null,
      //         state: "10",
      //         imghousestation: null,
      //         imgcompany: null,
      //         imgparentcompany: null,
      //         imgupload: "",
      //         memo: "",
      //         renteridcard: null,
      //         idcard1: "1313",
      //         idcard2: null,
      //         idcard3: null,
      //         houseAdminName: "小白楼房管站                                      "
      //       },
      //
      //     ]
      //   }
      // }
      // this.list = this.hanldelist(res.data.list)
      // this.total = res.data.total
      // this.listLoading = false;
      splittingFamilyList(data).then(res => {
        console.log(res)
        this.list = this.hanldelist(res.data.list)
        this.total = res.data.total
        this.listLoading = false;
      })
    },
    hanldelist(data){
      var arr=[];
      queryisAction(1).then(res=>{
        this.showids=res.data[0]
        for(var i in data){
          if(this.showids.includes(data[i].fid)){
            arr.push(data[i])
          }
        }
      })
      return arr;
    },
    shenheButton(type) {
      this.shenheName = type
    },
    handleSizeChange(val) {
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.splittingFamilyList()
    },
    handleCurrentChange(val) {
      this.listQuery.pageNum = val;
      this.splittingFamilyList()
    },

    resetForm() {
      this.listQuery.pageNum= 1,
          this.listQuery.pageSize= 20,
          this.listQuery.State= '',
          this.listQuery.Owner= '',
          this.listQuery.Addr= '',
          this.listQuery.FCode= '',
          this.listQuery.FGZManagerDate= '',
          this.listQuery.QGSDate= ''
    },
    // 提交
    handleTijiao(fid) {
      this.$confirm('请确认是否提交当前分户申请至“区公司”复核？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let data = {
          FID: fid,
          FGZCheck:localStorage.getItem('username')
        }
        splittingFamilySubmit(data).then(res => {
          this.$message({
            type: 'success',
            message: '提交成功!'
          });
          this.splittingFamilyList()
        })

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消提交'
        });
      });
    },

    handleAddUser(name, fid) {
      this.fid = fid

      this.typeName = name

      this.$router.push({
        path: '/system/xitongguanli/flowable/edit',
        query: { dialogName: name,fid:fid}
      })

    },
    // 保存
    save() {
      this.$refs.addForm.validate((valid) => {
        if (valid) {
          if (this.dialogName == '分户登记') {
            this.addSplittingFamily()
          } else if (this.dialogName == '分户修改' || this.dialogName == '总公司审核分户' || this.dialogName == '区公司复核分户') {
            this.updSplittingFamily()
          }
        } else {
          console.log('验证失败！');
          return false;
        }
      });


    },
    // 登记
    addSplittingFamily() {
      let data = this.addQuery
      this.listLoading = true;
      addSplittingFamily(data).then(res => {
        this.rester()
        this.listLoading = false;
        this.$message({
          type: 'success',
          message: '操作成功!'
        });
        this.splittingFamilyList()
      })
    },
    // 修改
    updSplittingFamily() {
      let data
      if (this.dialogName == '分户修改') {
        data = this.addQuery
      } else if (this.dialogName == '总公司审核分户') {
        data = this.shenheQuery
        if(data.zgsdate){
          data.zgsdate=dayjs(data.zgsdate).format('YYYY-MM-DD HH:mm:ss')
        }
      } else if (this.dialogName == '区公司复核分户') {
        data = this.fuheQuery
        if(data.qgsdate){
          data.qgsdate=dayjs(data.qgsdate).format('YYYY-MM-DD HH:mm:ss')
        }
      }
      data.fid = this.fid
      this.listLoading = true;
      updSplittingFamily(data).then(res => {
        console.log(res)
        this.rester()
        this.listLoading = false;
        this.$message({
          type: 'success',
          message: '操作成功!'
        });
        this.splittingFamilyList()
      })
    },
    handleUpdate(currentData) {
      //   一定要在打开弹窗前 再赋值 不然resetFiles没用
      this.dialogVisible = true;
      this.$nextTick(() => {});
    },
    // 详情
    splittingFamilyData() {
      let data = {
        FID: this.fid
      }
      splittingFamilyData(data).then(res => {
        console.log(res)
        this.addQuery = res.data
        this.addQuery.jizumianji = res.data.singlearea + res.data.mixarea

        this.fuheQuery.qgsview= res.data.qgsview,
            this.fuheQuery.qgscheck= res.data.qgscheck,
            this.fuheQuery.qgsdate= res.data.qgsdate
        this.shenheQuery.zgsdate= res.data.zgsdate,
            this.shenheQuery.zgsview= res.data.zgsview,
            this.shenheQuery.zgscheck= res.data.zgscheck
      })
    },
    // 重置
    rester() {
      this.addQuery = JSON.parse(this.newAddQuery)
    },
    handleDelete(fid) {
      this.$confirm('此操作将删除该条内容，请确认是否继续操作？', '删除提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let data = {
          FID:fid
        }
        delSplittingFamilySubmit(data).then(res=>{
          console.log(res)
          this.splittingFamilyList()
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
          .then(_ => {
            done();

            this.rester()
          })
          .catch(_ => {});
    },
    // 扫描件上传
    handleUploadScan() {
      console.log(1)
      this.uploadDialogVisible = true;
    },
    uploadClose(){
      this.uploadDialogVisible = false
    },
    uploadConfirm(fileList){
      let ImgUpload = []
      fileList.forEach((item,index)=>{
        ImgUpload.push(item.response.data.url)
      })
      this.addQuery.ImgUpload = JSON.stringify(ImgUpload)
      this.uploadDialogVisible = false
    },
    handleout() {
      this.$confirm('此操作将导出该条内容，请确认是否继续操作？', '导出提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
          .then(() => {
            let data = {
              pageNum: this.listQuery.pageNum,
              pageSize: this.listQuery.pageSize,
              State: this.listQuery.State,
              Owner: this.listQuery.Owner,
              Addr: this.listQuery.Addr,
              FCode: this.listQuery.FCode,
              FGZManagerDate: this.listQuery.FGZManagerDate ? dayjs(this.listQuery.FGZManagerDate).format(
                  'YYYY-MM-DD HH:mm:ss') : '',
              QGSDate: this.listQuery.QGSDate ? dayjs(this.listQuery.QGSDate).format('YYYY-MM-DD HH:mm:ss') : ''
            }
            splittingFamilyList(data).then(res => {
              let list = res.data.list
              let outList = []
              list.forEach((item, index) => {
                outList.push({
                  '管理部(分中心)': item.houseAdminName,
                  '业务编号': item.fcode,
                  '承租人': item.owner,
                  '房屋地址': item.addr,
                  '合同编号': item.contractno,
                  '产别': item.realway,
                  '房管站核实时间':item.fgzmanagerdate?item.fgzmanagerdate.split(' ')[0]:'',
                  '状态':item.state==-1?'区住建委退回':item.state==-2?'抽查不通过':item.state=='00'?'未提交':
                      item.state==10?'数据录入完毕':item.state==20?'等待区住建委核查':item.state==40?'抽查通过':
                          item.state==50?'区住建委核查通过':''
                })
              })
              // 获取表格数据
              const data = outList
              // 转换数据为工作表
              const worksheet = XLSX.utils.json_to_sheet(data)
              // 创建新的工作簿
              const workbook = XLSX.utils.book_new()
              // 将工作表添加到工作簿
              XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1')
              // 导出Excel文件
              XLSX.writeFile(workbook, '所资料.xlsx')
            })
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消导出'
            })
          })
    }
  },
};
</script>
<style scoped>
.tianjiaButton {
  border: 2px solid #008C93;
  background-color: #fff;
  color: #008C93;
}

.xinxi {
  display: flex;
  width: 800px;
}

.goufangContent {
  width: 100%;
  box-sizing: border-box;
  padding: 20px;
  background-color: #F7F7F7;
}

.tabButton {
  background: #EFF2F7;
  color: #333333;
  border: none;
}

.saveContent {
  width: 100%;
  display: flex;
  justify-content: end;
  margin-top: 20px;
  padding-bottom: 20px;
}



/dee/.el-date-editor {
  width: 120px !important;
}

/deep/.el-input__inner{
  width: 160px;
}
/deep/.publicpaginationview .el-input__inner{
  width: 100px;
}
/deep/.publicpaginationview .is-in-pagination .el-input__inner{
  width: 50px;
}
</style>
